home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBGRX100.ARJ / CLIPPING.H < prev    next >
Text File  |  1992-04-10  |  4KB  |  105 lines

  1. /** 
  2.  ** CLIPPING.H 
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #ifndef _CLIPPING_H_
  25. #define _CLIPPING_H_
  26.  
  27. #define INSIDE        0
  28. #define CLIPPED        1
  29. #define OUTSIDE        2
  30.  
  31. #ifndef WHEN_CLIPPED
  32. #define WHEN_CLIPPED
  33. #endif
  34.  
  35. #ifndef WHEN_OUTSIDE
  36. #define WHEN_OUTSIDE    return
  37. #endif
  38.  
  39. #define CLIPDOT(c,xx,yy) {                        \
  40.     if((xx > c->gc_xcliphi) || (xx < c->gc_xcliplo)) { WHEN_OUTSIDE; }  \
  41.     if((yy > c->gc_ycliphi) || (yy < c->gc_ycliplo)) { WHEN_OUTSIDE; }  \
  42. }
  43.  
  44. #define CLIPDOTTOCONTEXT(c,xx,yy) {                    \
  45.     if((xx > c->gc_xmax) || (xx < 0)) { WHEN_OUTSIDE; }            \
  46.     if((yy > c->gc_ymax) || (yy < 0)) { WHEN_OUTSIDE; }            \
  47. }
  48.  
  49. #define CLIPHLINE(c,x1,x2,yy) {                        \
  50.     if(x1 > x2) EXCHG(x1,x2);                        \
  51.     if((x1 > c->gc_xcliphi) || (x2 < c->gc_xcliplo)) { WHEN_OUTSIDE; }  \
  52.     if((yy > c->gc_ycliphi) || (yy < c->gc_ycliplo)) { WHEN_OUTSIDE; }  \
  53.     if(x1 < c->gc_xcliplo) { x1 = c->gc_xcliplo; WHEN_CLIPPED; }    \
  54.     if(x2 > c->gc_xcliphi) { x2 = c->gc_xcliphi; WHEN_CLIPPED; }    \
  55. }
  56.  
  57. #define CLIPVLINE(c,xx,y1,y2) {                        \
  58.     if(y1 > y2) EXCHG(y1,y2);                        \
  59.     if((xx > c->gc_xcliphi) || (xx < c->gc_xcliplo)) { WHEN_OUTSIDE; }  \
  60.     if((y1 > c->gc_ycliphi) || (y2 < c->gc_ycliplo)) { WHEN_OUTSIDE; }  \
  61.     if(y1 < c->gc_ycliplo) { y1 = c->gc_ycliplo; WHEN_CLIPPED; }    \
  62.     if(y2 > c->gc_ycliphi) { y2 = c->gc_ycliphi; WHEN_CLIPPED; }    \
  63. }
  64.  
  65. #define CLIPBOXTEST(c,x1,y1,x2,y2) {                    \
  66.     if((x1 > c->gc_xcliphi) || (x2 < c->gc_xcliplo)) { WHEN_OUTSIDE; }  \
  67.     if((y1 > c->gc_ycliphi) || (y2 < c->gc_ycliplo)) { WHEN_OUTSIDE; }  \
  68. }
  69.  
  70. #define CLIPBOXSORTANDTEST(c,x1,y1,x2,y2) {                \
  71.     if(x1 > x2) EXCHG(x1,x2);                        \
  72.     if(y1 > y2) EXCHG(y1,y2);                        \
  73.     CLIPBOXTEST(c,x1,y1,x2,y2);                        \
  74. }
  75.  
  76. #define CLIPBOX(c,x1,y1,x2,y2) {                    \
  77.     CLIPBOXSORTANDTEST(c,x1,y1,x2,y2);                    \
  78.     if(x1 < c->gc_xcliplo) { x1 = c->gc_xcliplo; WHEN_CLIPPED; }    \
  79.     if(y1 < c->gc_ycliplo) { y1 = c->gc_ycliplo; WHEN_CLIPPED; }    \
  80.     if(x2 > c->gc_xcliphi) { x2 = c->gc_xcliphi; WHEN_CLIPPED; }    \
  81.     if(y2 > c->gc_ycliphi) { y2 = c->gc_ycliphi; WHEN_CLIPPED; }    \
  82. }
  83.  
  84. #define CLIPSORTEDBOX(c,x1,y1,x2,y2) {                    \
  85.     CLIPBOXTEST(c,x1,y1,x2,y2);                        \
  86.     if(x1 < c->gc_xcliplo) { x1 = c->gc_xcliplo; WHEN_CLIPPED; }    \
  87.     if(y1 < c->gc_ycliplo) { y1 = c->gc_ycliplo; WHEN_CLIPPED; }    \
  88.     if(x2 > c->gc_xcliphi) { x2 = c->gc_xcliphi; WHEN_CLIPPED; }    \
  89.     if(y2 > c->gc_ycliphi) { y2 = c->gc_ycliphi; WHEN_CLIPPED; }    \
  90. }
  91.  
  92. #define CLIPBOXTOCONTEXT(c,x1,y1,x2,y2) {                \
  93.     if(x1 > x2) EXCHG(x1,x2);                        \
  94.     if(y1 > y2) EXCHG(y1,y2);                        \
  95.     if((x1 > c->gc_xmax) || (x2 < 0)) { WHEN_OUTSIDE; }            \
  96.     if((y1 > c->gc_ymax) || (y2 < 0)) { WHEN_OUTSIDE; }            \
  97.     if(x1 < 0) { x1 = 0; WHEN_CLIPPED; }                \
  98.     if(y1 < 0) { y1 = 0; WHEN_CLIPPED; }                \
  99.     if(x2 > c->gc_xmax) { x2 = c->gc_xmax; WHEN_CLIPPED; }        \
  100.     if(y2 > c->gc_ymax) { y2 = c->gc_ymax; WHEN_CLIPPED; }        \
  101. }
  102.  
  103. #endif /* whole file */
  104.  
  105.